import unittest
import requests

class TestIhrmLogin(unittest.TestCase):
    # 测试方法1，登录成功
    def test01_login_success(self):
        # 组织url
        url = "http://ihrm-test.itheima.net/api/sys/login"
        header = {"Content-Type": "application/json"}
        json_data = {"mobile": "13800000002", "password": "123456"}
        resp = requests.post(url=url, headers=header, json=json_data)
        print("登录成功：", resp.json())
#         # 断言
#         self.assertEqual(200, resp.status_code)
#         self.assertEqual(True, resp.json().get("success"))
#         self.assertEqual(10000, resp.json().get("code"))
#         self.assertIn("操作成功", resp.json().get("message"))
#     # 测试方法2，密码错误
#     def test02_pwd_err(self):
#         # 组织url
#         url = "http://ihrm-test.itheima.net/api/sys/login"
#         header = {"Content-Type": "application/json"}
#         json_data = {"mobile": "13800000002", "password": "123456789"}
#         resp = requests.post(url=url, headers=header, json=json_data)
#         print("密码错误：", resp.json())
#         # 断言
#         self.assertEqual(200, resp.status_code)
#         self.assertEqual(False, resp.json().get("success"))
#         self.assertEqual(20001, resp.json().get("code"))
#         self.assertIn("用户名或密码错误", resp.json().get("message"))


# 添加员工
# import requests
#
# url = "http://ihrm-test.itheima.net/api/sys/user"
# header ={"Content-Type": "application/json","Authorization":"Bearer f920856a-6ace-40a9-870b-71dc1d4d97d5"}
# json = {
#     "username": "小猪佩奇",
#     "mobile": "13900087653",
#     "workNumber": "9527"
# }
# resp = requests.post(url=url,headers=header, json=json)
# print("添加员工", resp.json())
# # 查询员工
# url_search ="http://ihrm-test.itheima.net/api/sys/user/1528726824459239424"
# header_search = {"Content-Type": "application/json",
#                  "Authorization": "Bearer f920856a-6ace-40a9-870b-71dc1d4d97d5"}
# resp_search = requests.get(url= url_search,headers= header_search)
# print("查询员工", resp_search.json())
# # 修改员工
# url_modify ="http://ihrm-test.itheima.net/api/sys/user/1528726824459239424"
# header_modify ={"Content-Type": "application/json",
#                  "Authorization": "Bearer f920856a-6ace-40a9-870b-71dc1d4d97d5"}
# json_modify =  {
# "username":"齐天大圣"
# }
# resp_modify= requests.put(url= url_modify,headers= header_modify,json=json_modify)
# print("修改员工", resp_modify.json())
#
#
# # 删除员工
# url_delete ="http://ihrm-test.itheima.net/api/sys/user/1528726824459239424"
# header_delete = {"Content-Type": "application/json","Authorization": "Bearer f920856a-6ace-40a9-870b-71dc1d4d97d5"}
# resp_delete= requests.delete(url= url_delete,headers= header_delete)
# print("删除员工", resp_delete.json())
